import request, {
  requestPostByToken,
  requestGetByToken,
  requestPutByToken,
  requestDeleteByToken,
} from '@/utils/request';

import URI from './uri';

export async function accountLogin(params) {
  const { userName, password } = params;
  // const keys = localStorage.getItem('USER_KEY')
  // console.log('keyskeys', keys)
  // return
  const response = await request(URI.common.login, {
    method: 'POST',
    data: {
      user_name: userName,
      password,
    },
  });
  if (response) {
    sessionStorage.setItem('USER_KEY', userName)
    return {
      response: {
        ...response,
        roleId: response.role_id,
      },
      status: 'ok',
    };
  }
  return {
    status: 'error',
  };
}

export async function logout() {
  return requestGetByToken({
    url: URI.common.logout,
  });
}

export async function getFakeCaptcha(mobile) {
  return request(`/api/login/captcha?mobile=${mobile}`);
}
